<template>
    <div class="container">
      <!-- 搜索区域 -->
      <div class="search-box">
        <div class="search-item">
          <label>挂号单号</label>
          <input type="text" placeholder="请输入挂号单号" v-model="searchForm.registerId">
        </div>
        <div class="search-item">
          <label>患者名称</label>
          <input type="text" placeholder="请输入患者名称" v-model="searchForm.patientName">
        </div>
        <button class="query-btn" @click="handleSearch">Q查询</button>
      </div>
  
      <!-- 退费订单表格 -->
      <table class="order-table">
        <thead>
          <tr>
            <th>退费订单号</th>
            <th>挂号单号</th>
            <th>患者姓名</th>
            <th>退费总金额</th>
            <th>退费方式</th>
            <th>订单状态</th>
            <th>创建时间</th>
          </tr>
        </thead>
        <tbody>
          <tr v-for="(order, index) in paginatedData" :key="order.id" 
              :class="{ 'zebra': index % 2 }"
              @click="toggleDetails(order)">
            <td>{{ order.refundId }}</td>
            <td>{{ order.registerId }}</td>
            <td>{{ order.patient }}</td>
            <td>¥{{ order.amount }}</td>
            <td>{{ order.paymentType }}</td>
            <td>
              <span class="status-refunded">{{ order.status }}</span>
            </td>
            <td>{{ order.createTime }}</td>
          </tr>
        </tbody>
      </table>
  
      <!-- 处方详情表格 -->
      <div v-if="showDetails" class="prescription-details">
        <table class="detail-table">
          <thead>
            <tr>
              <th>详情ID</th>
              <th>处方ID</th>
              <th>名称</th>
              <th>价格</th>
              <th>数量</th>
              <th>小计</th>
              <th>类型</th>
              <th>状态</th>
            </tr>
          </thead>
          <tbody>
            <tr v-for="item in currentDetails" :key="item.id">
              <td>{{ item.detailId }}</td>
              <td>{{ item.prescriptionId }}</td>
              <td>{{ item.name }}</td>
              <td>¥{{ item.price }}</td>
              <td>{{ item.quantity }}</td>
              <td>¥{{ item.subtotal }}</td>
              <td>{{ item.type }}</td>
              <td>{{ item.status }}</td>
            </tr>
          </tbody>
        </table>
      </div>
  
      <!-- 分页组件 -->
      <div class="pagination">
        <span class="total">共{{ total }}条</span>
        <select v-model="pageSize">
          <option>6</option>
          <option>10</option>
          <option>20</option>
        </select>
        <span>条/页</span>
        <button v-for="page in totalPages" 
                :key="page"
                :class="{ active: currentPage === page }"
                @click="currentPage = page">
          {{ page }}
        </button>
        <input type="text" v-model="inputPage">
        <button @click="goToPage">前往</button>
        <span>页</span>
      </div>
    </div>
  </template>
  
  <script setup>
  import { ref, computed } from 'vue'
  
  // 搜索表单
  const searchForm = ref({
    registerId: '',
    patientName: ''
  })
  
  // 分页相关
  const currentPage = ref(1)
  const pageSize = ref(6)
  const inputPage = ref(1)
  
  // 订单数据
  const orders = ref([
    {
      refundId: 'ODC1806572412448407552',
      registerId: 'GH1806571183798353920',
      patient: '唐军鹏',
      amount: 50,
      paymentType: '支付宝',
      status: '已退费',
      createTime: '2024/8/28 14:19:26',
      details: [
        {
          detailId: 'ITEM180857181385377152',
          prescriptionId: 'CO1806871913212985344',
          name: 'CT',
          price: 50,
          quantity: 1,
          subtotal: 50,
          type: '检查',
          status: '已退费'
        }
      ]
    },
    // 其他订单数据...
  ])
  
  // 详情展示
  const showDetails = ref(false)
  const currentDetails = ref([])
  
  // 分页计算
  const total = computed(() => orders.value.length)
  const totalPages = computed(() => Math.ceil(total.value / pageSize.value))
  const paginatedData = computed(() => {
    const start = (currentPage.value - 1) * pageSize.value
    return orders.value.slice(start, start + pageSize.value)
  })
  
  // 方法
  function toggleDetails(order) {
    currentDetails.value = order.details
    showDetails.value = !showDetails.value
  }
  
  function handleSearch() {
    // 实现搜索逻辑
  }
  
  function goToPage() {
    currentPage.value = Math.min(Math.max(1, inputPage.value), totalPages.value)
  }
  </script>
  
  <style scoped>
  .container {
    font-family: 'Microsoft YaHei', Arial, sans-serif;
    padding: 20px;
    background: #fff;
  }
  
  .search-box {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
  }
  
  .search-item {
    display: flex;
    align-items: center;
    gap: 8px;
  }
  
  .search-item input {
    padding: 6px 12px;
    border: 1px solid #dcdfe6;
    border-radius: 4px;
    width: 180px;
  }
  
  .query-btn {
    background: #409EFF;
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.3s;
  }
  
  .query-btn:hover {
    background: #66b1ff;
  }
  
  .order-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 10px;
  }
  
  .order-table th, .order-table td {
    border: 1px solid #ebeef5;
    padding: 12px;
    text-align: center;
    font-size: 14px;
  }
  
  .order-table th {
    background: #f5f7fa;
    color: #606266;
    font-weight: 500;
  }
  
  .zebra {
    background-color: #fafafa;
  }
  
  .status-refunded {
    color: #67c23a;
    padding: 4px 8px;
    border-radius: 4px;
  }
  
  .prescription-details {
    margin: 15px 0;
    border: 1px solid #ebeef5;
  }
  
  .detail-table {
    width: 100%;
    border-collapse: collapse;
  }
  
  .detail-table th, .detail-table td {
    border: 1px solid #ebeef5;
    padding: 10px;
    font-size: 13px;
    color: #606266;
  }
  
  .pagination {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 20px;
  }
  
  .pagination button {
    padding: 5px 10px;
    border: 1px solid #ddd;
    background: #fff;
    cursor: pointer;
  }
  
  .pagination button.active {
    background: #409EFF;
    color: white;
    border-color: #409EFF;
  }
  
  .pagination input {
    width: 40px;
    padding: 4px;
    text-align: center;
  }
  </style>